if ( window.XDomainRequest ) { jQuery.ajaxTransport(function( s ) { if ( s.crossDomain /*&& s.async*/ ) { if ( s.timeout ) { s.xdrTimeout = s.timeout; delete s.timeout; } var xdr; return { send: function( _, complete ) { function callback( status, statusText, responses, responseHeaders ) { xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop; xdr = undefined; complete( status, statusText, responses, responseHeaders ); } xdr = new XDomainRequest(); xdr.onload = function() { callback( 200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType ); }; xdr.onerror = function() { callback( 404, "Not Found" ); }; xdr.onprogress = jQuery.noop; xdr.ontimeout = function() { callback( 0, "timeout" ); }; xdr.timeout = s.xdrTimeout || Number.MAX_VALUE; xdr.open( s.type, s.url ); xdr.send( ( s.hasContent && s.data ) || null ); }, abort: function() { if ( xdr ) { xdr.onerror = jQuery.noop; xdr.abort(); } } }; } }); } var vn_sessionid = ''; var vn_language = 'it'; //Additional currencies var MYR = 'MYR'; if(vn_sessionid==''){ var jqXHR=$.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/shop/getSession.jsp', data: { _: new Date().getTime() }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', timeout: 1000, success: function(json){ vn_sessionid=json.jsessionid; $.ajax({ type: 'get', url: '/webservices/saveVnSession.jsp', data: { jsessionid: vn_sessionid } }) } }); } simpleCart.checkoutTo="Custom"; simpleCart.currency= 'EUR'; //$.support.cors = true; CartItem.prototype._link = function(outputValue){ return ''+outputValue+''; }; var timeout_hoverCart; function toggleCart(){ if(simpleCart.quantity===0){ $('.cartInfo').hide(); $('.hoverCart').hide(); }else{ $('.cartInfo').show(); } } function getProductInfo(_productId, callback){ $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/getProductInfo.jsp;jsessionid='+vn_sessionid, data: { productId: _productId, _: new Date().getTime() }, dataType:'json', cache: false, success: function(json){ callback(json); } }); } function getBundleInfo(_bundleId, callback){ $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/getProductInfo.jsp;jsessionid='+vn_sessionid, data: { showOffers: true, limit: 0, offerId: _bundleId, _: new Date().getTime() }, dataType:'json', cache: false, success: function(json){ callback(json); } }); } function getProductsChildInfo(_productId, callback){ $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/getProductChildsInfo.jsp;jsessionid='+vn_sessionid, data: { parentId: _productId, _: new Date().getTime() }, dataType:'json', cache: false, success: function(json){ callback(json); } }); } function send_stats(productId, event, label){ if(typeof typeof push_stats != 'undefined' ){ push_stats('Il Tempo', event, label); } } function popolateCart(cart){ simpleCart.clear(); simpleCart.currency = cart.currency; $.each( cart.items, function(index, prodotto){ if (prodotto.product.custom1) { prodotto.product.productName = prodotto.product.custom1 + ' - ' + prodotto.product.productName; } if (prodotto.product.custom2) { prodotto.product.imageAbsoluteLink = $(prodotto.product.custom2).attr('src'); } simpleCartAdd(prodotto,prodotto.cartQuantity); }); } function addBundle(bundleId){ $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/shop/cartAdd.jsp;jsessionid='+vn_sessionid, data: { offerId: bundleId, _: new Date().getTime(), language: vn_language }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { if(json.success){ popolateCart(json.cart); if(typeof stats != 'undefined' ){ getBundleInfo(bundleId, function(json){ try{ send_stats(bundleId, stats.event.addBundle, json[0].name); }catch(e){} }); } $('.hoverCart').show(); timeout_hoverCart=window.setTimeout(function(){ $('.hoverCart').hide() },5000); } } }); } //show added article message var showMessageAfterSuccess = false; function addProduct(item, disable_alert){ var dataParameters = { productId: item.productid, _: new Date().getTime(), language: vn_language }; if(item.issues){ dataParameters.elementId = item.issues; } function _addProduct() { $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/shop/cartAdd.jsp;jsessionid='+vn_sessionid, data: dataParameters, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { if(json.success){ //aggiungo var prodotto; $.each(json.cart.items, function(index, _prodotto){ if( parseInt(_prodotto.product.productId,10) == item.productid ){ prodotto=_prodotto; return false; } }); if(typeof prodotto !== 'undefined'){ if(!disable_alert){ if( showMessageAfterSuccess ){ if ($.isFunction(showAddedArticleMessage)) { showMessageAfterSuccess = false; showAddedArticleMessage(); } } } else { if( showMessageAfterSuccess ){ if ($.isFunction(myfunc)) { showMessageAfterSuccess = false; showAddedArticleMessage(); } } } popolateCart(json.cart) if(typeof stats != 'undefined' ){ send_stats(item.productid, stats.event.addProduct, prodotto.product.productName); } $('.hoverCart').show(); timeout_hoverCart=window.setTimeout(function(){ $('.hoverCart').hide() },5000); } }else{ var errorMessage = json.errorMessage; $.confirm({ 'title' : '', 'message' : errorMessage, 'buttons' : {'Ok':{'class':'blue'}} }); } } }); } if (item.mediaId) { $.ajax({ url: '/actions/getMedia.jsp', dataType: 'json', data: { 'id[]': item.mediaId }, success: function( medias ){ var media = medias[0]; dataParameters['custom1['+item.productid+']'] = media.title; dataParameters['custom2['+item.productid+']'] = ''; _addProduct(); } }); } else { _addProduct(); } } var removingProduct=false; function removeProduct(item,removeAll){ if(removingProduct) return; removingProduct=true; $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/shop/cartRemove.jsp;jsessionid='+vn_sessionid, data: { productId: item.productid, removeAll: (removeAll), _: new Date().getTime(), elementId: item.issues }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { popolateCart(json.cart); if(typeof stats != 'undefined' ){ getProductInfo(item.productid, function(prodotto){ send_stats(item.productid, stats.event.removeProduct, prodotto[0].productName); }); } if(removeAll){ $('.add_simpleCart.simpleCartItemAdded').removeClass('simpleCartItemAdded'); }else if(item.productid){ $('.add_simpleCart[data-productid="'+item.productid+'"]').removeClass('simpleCartItemAdded'); } removingProduct=false; } }); } function simpleCartAdd(prodotto,quantity){ var image = ''; if(prodotto.product.imageAbsoluteLink){ image=prodotto.product.imageAbsoluteLink; }else if(prodotto.product.imageLink){ image='https://www.iltempo.it/resizer_ext.jsp?w=100&h=-1&maximize=true&img='+encodeURIComponent(prodotto.product.imageLink); } var description = '' + prodotto.product.productName + ''; if ( prodotto.product.productDescription.length > 0 ) { description += '\n' + prodotto.product.productDescription + ''; } simpleCart.add('productid='+prodotto.product.productId, 'issues='+prodotto.product.issues, 'quantity='+(typeof quantity === "undefined"?1:quantity), 'price='+prodotto.singlePrice, 'descrizione='+description.replace(new RegExp('\n', 'g'),'
') , 'immagine='+image ); $('.add_simpleCart[data-productid="'+prodotto.product.productId+'"]').addClass('simpleCartItemAdded'); } // refreshCart window.setInterval(function(){ var currentItems = {}; simpleCart.each(function(item){ currentItems[item.id] = {}; simpleCart.each( item , function( value , x , name ){ if( name !== "id" ){ currentItems[item.id][name] = value; } }); }); currentItems = escape( JSON.stringify( currentItems ) ); simpleCart.load(); simpleCart.updateTotals(); if(localStorage.getItem('sc_simpleCart_items') !== currentItems){ simpleCart.update(); } toggleCart(); }, 1000); simpleCart.bind('afterAdd', function(){ toggleCart(); }); simpleCart.bind('afterRemove', function(){ toggleCart(); }); simpleCart.bind('beforeIncrement', function(item){ addProduct(item, true); return false; }); simpleCart.bind('beforeDecrement', function(item){ removeProduct(item, false); }); simpleCart.bind('beforeRemove', function(item){ removeProduct(item,true); }); simpleCart.bind('afterEmpty', function(){ toggleCart(); $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/shop/cartRemove.jsp;jsessionid='+vn_sessionid, data: { clearCart: true, _: new Date().getTime() }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { } }); }); simpleCart.bind('customCheckout', function(){ location.href= '/widget/shop/pre_checkout.jsp?cartUrl='+encodeURIComponent(location.href)+(typeof checkoutParameters != 'undefined'?'&'+checkoutParameters:''); }); simpleCart.ready(function(){ if (simpleCart.quantity > 0) { $.ajax({ type: 'get', url: 'https://edicola.iltempo.it/iltempo//webservice/shop/cart.jsp;jsessionid='+vn_sessionid, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { simpleCart.clear(); if(json) popolateCart(json.cart); } }); } }); //Override of currency managment in the simpleCart.js script simpleCart.currencySymbol = function() { switch(simpleCart.currency){ case CHF: return "CHF "; case CZK: return "CZK "; case DKK: return "DKK "; case HUF: return "HUF "; case NOK: return "NOK "; case PLN: return "PLN "; case SEK: return "SEK "; case JPY: return "¥"; case EUR: return "€"; case GBP: return "£"; case CHF: return "CHF "; case THB: return "฿"; case MYR: return "RM "; case USD: case CAD: case AUD: case NZD: case HKD: case SGD: return "$"; default: return ""; } }; $(function(){ toggleCart(); $('.cartInfo').bind('mouseenter mouseover click',function(){ try{ window.clearTimeout(timeout_hoverCart); }catch(e){} $('.cartInfo').bind('mouseleave mouseout ',function(){ $('.hoverCart').hide(); }); $('.hoverCart').show(); }); $('.hoverCart').bind('mouseenter mouseover click',function(){ try{ window.clearTimeout(timeout_hoverCart); }catch(e){} $('.hoverCart').show(); $('.cartInfo').unbind('mouseleave mouseout'); $('.hoverCart').bind('mouseleave mouseout',function(){ $('.hoverCart').hide(); }); }); //evento aggiunta carrello $(document).on('click','.add_simpleCart[data-productid]',function(){ var productId=parseInt($(this).attr('data-productid'),10); var productType=parseInt($(this).data('type'),10); var mediaId=$(this).attr('mediaid'); var item={}; item.productid = productId; if(mediaId){ item.mediaId = mediaId; item.issues = 'MEDIA-'+mediaId; } if(productType==0 || isNaN(productType)) addProduct(item, false); else addBundle(productId); }); //evento oggetto non disponibile $(document).on('click','.disponibilita_0[data-productid]',function(){ $.confirm({ 'title' : '', 'message' : 'Prodotto non disponibile', 'buttons' : {'Ok':{'class':'blue'}} }); }); });